//index.js
//获取应用实例
const app = getApp()
function getRandomColor() {
  let rgb = [];
  for (let i = 0; i < 3; i++) {
    let color = Math.floor(Math.random() * 256).toString(16);
    color = color.length == 1 ? '0' + color : color;
    rgb.push(color)
  }
  return "#" + rgb.join("");
}
Page({
  data: {
    danmuValue: "",
    danmuList: [{
      text: "这是第1条弹幕",
      color: "#ff0000",
      time: 1
    }, {
      text: "这是第2条弹幕",
      color: "#00ff00",
      time: 3
    }, {
      text: "这是第3条弹幕",
      color: "#0000ff",
      time: 6
    }]
  },
  onReady: function () {
    this.videoContext = wx.createVideoContext("myVideo");
    //console.log(this.videoContext)
  },
  playVideo: function () {
    this.videoContext.play();
  },
  pauseVideo: function () {
    this.videoContext.pause();
  },
  seekVideo: function () {
    this.videoContext.seek(100);
  },
  inputBlur: function (e) {
    console.log(e.detail.value)
    this.setData({
      danmuValue: e.detail.value
    })
  },
  sendDanmu: function () {
    this.videoContext.sendDanmu({
      text: this.data.danmuValue,
      color: getRandomColor()
    })
  }
})